package com.iengoo.inductionms.service.impl;

import com.iengoo.inductionms.entity.Department;
import com.iengoo.inductionms.mapper.DepartmentMapper;
import com.iengoo.inductionms.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zpym
 * @CopyRight (C) http://www.iengoo.com
 * @brief
 * @email 122162005@qq.com
 * @date 2019-03-10 15:05
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<Department> query() {
        return departmentMapper.query();
    }
    //根据部门简称获取部门人数
    @Override
    public String queryDepartmentNum(String documentSimple) {
        //根据部门简称查询部门信息
        Department department = departmentMapper.queryDepartmentNumAndCode(documentSimple);
        //获取部门总人数
        Integer departmentNum = department.getDepartmentNum();
        //获取部门编号
        String departmentCode = department.getDepartmentCode();
        StringBuffer stringBuffer = new StringBuffer(departmentCode);
        //自动生成员工编号,员工所在部门的人数统计+1;
        if (departmentNum < 10) {
            stringBuffer.append("00" + departmentNum);
        }if (departmentNum >=10 && departmentNum <100) {
            stringBuffer.append("0" + departmentNum);
        }else if(departmentNum >= 100 && departmentNum < 1000) {
            stringBuffer.append(departmentNum);
        }
        return stringBuffer.toString();
    }
}
